<template>
  <div class="search">
    <f-form ref="form" :action="api.company.setAuditState" :form-key="this.formItem.companyId" handler-name="comapnyAuthSuccessHandler">
      <f-form-item label="审核状态" name="auditState" :required="true" v-if="loaded" type="radio" :data="auditStateArray"  data-type="number" :value.sync="formItem.auditState"/>
      <f-form-item label="企业账户名" name="accountName" :required="true" :disabled="disabled" :value="formItem.accountName"/>
      <f-form-item label="登录密码" name="password" :required="true" :disabled="disabled" v-if="formItem.auditState==2|| formItem.auditState==''" :value="formItem.password"/>
      <f-form-item label="账户角色" name="roleId" type="select" :required="true" v-if="formItem.auditState==2|| formItem.auditState==''" :data="api.role.listByType('1')" :value="formItem.roleId" label-key="roleName" value-key="roleId"/>
      <f-form-item label="退回原因" name="auditContent" :required="true" type="textarea" :value.sync="formItem.auditContent" v-if="formItem.auditState==10"/>
    </f-form>
  </div>
</template>

<script>

  export default {
    name: 'CompanyAudit',
    props: {},
    data() {
      return {
        saving: false,
        loaded: false,
        disabled: false,
        auditStateArray: [],
        modalVisible: false,
        formItem: this.getFormItem()
      }
    },
    computed: {
      modalTitle: function() {
        return '企业审核-' + this.formItem.companyName
      }
    },

    methods: {
      getFormItem() {
        return {
          auditState: 1,
          roleId: '4',
          password: '123456'
        }
      },
      setData(data) {
        this.$refs.form.resetFields()
        if (data && data.companyId) {
          this.http.get(this, {
            url: this.api.company.get,
            params: {
              companyId: data.companyId
            },
            success: function(me, data) {
              me.loaded = true
              me.formItem = data
              me.formItem.accountName = data.linkTel
              me.formItem.password = '123456'
              if (data.auditState == 1) {
                me.auditStateArray = [{ label: '待审核', value: 1 }, { label: '通过', value: 2 }, { label: '退回', value: 10 }]
              }
              if (data.auditState == 2) {
                me.auditStateArray = [{ label: '反审核', value: 1 }, { label: '退回', value: 10 }]
                me.disabled = true
                me.formItem.auditState = ''
              }
              if (data.auditState == 10) {
                me.auditStateArray = [{ label: '反审核', value: 1 }, { label: '通过', value: 2 }]
              }
            }
          })
          this.isAdd = false
        } else {
          this.formItem = this.getFormItem()
          this.loaded = true
        }
      },
      handleSubmit(callback) {
        let params = {
          companyId: this.formItem.companyId,
          nickName: this.formItem.companyName
        }
        this.$refs.form.handlerSubmit(params, callback)
      }
    },
    created() {

    },
    components: {}
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
